home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_xemacs.idb / usr / freeware / lib / xemacs-20.4 / lisp / edebug / edebug-cl-read.el.z / edebug-cl-read.el
Encoding:
Text File  |  1998-05-21  |  4.2 KB  |  119 lines

  1. ;;; edebug-cl-read.el --- Edebug reader macros for use with cl-read.
  2.  
  3. ;; Copyright (C) 1993 Daniel LaLiberte
  4. ;; Author: Daniel LaLiberte <liberte@cs.uiuc.edu>
  5. ;; Keywords: lisp, tools, maint
  6.  
  7. ;; This file is part of XEmacs.
  8.  
  9. ;; XEmacs is free software; you can redistribute it and/or modify it
  10. ;; under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation; either version 2, or (at your option)
  12. ;; any later version.
  13.  
  14. ;; XEmacs is distributed in the hope that it will be useful, but
  15. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  17. ;; General Public License for more details.
  18.  
  19. ;; You should have received a copy of the GNU General Public License
  20. ;; along with XEmacs; see the file COPYING.  If not, write to the Free
  21. ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  22. ;; 02111-1307, USA.
  23.  
  24. ;;; Synched up with: Not in FSF
  25.  
  26. ;;; Commentary:
  27.  
  28. ;; LCD Archive Entry:
  29. ;; edebug-cl-read.el|Daniel LaLiberte|liberte@cs.uiuc.edu
  30. ;; |Edebug reader macros for cl-read.el
  31. ;; |$Date: 1993/09/21 21:06:30 $|$Revision: 1.0 $|~/modes/edebug-cl-read.el|
  32.  
  33. ;; If you use cl-read.el and want to use edebug with any code
  34. ;; in a file written with CL read syntax, then you need to use this
  35. ;; package.
  36.  
  37. ;; To Do:
  38. ;; Handle shared structures, but this is not normally used in executable code.
  39.  
  40. ;; Read-time evaluation shouldn't be used in a form argument since
  41. ;; there is no way to instrument the result of the evaluation, and
  42. ;; no way to tell Edebug not to try.  
  43.  
  44. ;; Need to mangle all local variable names that might be visible to
  45. ;; eval, e.g. stream, char.  Alternatively, packages could hide them.
  46.  
  47. ;;; Code:
  48.  
  49. (require 'cl)
  50. ;; For byte compiling cl-read is needed.
  51. ;; But edebug-cl-read should not even be loaded unless cl-read already is.
  52. (require 'cl-read)
  53.  
  54. (provide 'edebug-cl-read)
  55. ;; Do the above provide before the following require to avoid load loop.
  56. (require 'edebug)
  57.  
  58. (defvar reader::stack)
  59.  
  60. ;; The following modifications of reader functions
  61. ;; could be done via advice.  But we need to switch between
  62. ;; edebug versions and originals frequently.  Also advice.el 
  63. ;; doesn't support advising anonymous functions.
  64.  
  65. (defun edebug-reader::read-sexp-func (point func)
  66.   ;; dummy def
  67.   )
  68.  
  69. (defvar edebug-read-dotted-list)
  70.  
  71. (defun edebug-read-sexp-func (point func)
  72.   "Edebug offset storing is happening."
  73.   (edebug-storing-offsets point
  74.     (let (edebug-read-dotted-list)
  75.       (edebug-reader::read-sexp-func point func))))
  76.  
  77. (defun edebug-end-list-handler (stream char)
  78.   ;; If the dotted form is a list, signal to offset routines.
  79.   (setq edebug-read-dotted-list (listp (car reader::stack)))
  80.   (edebug-reader::end-list-handler stream char))
  81.  
  82.  
  83. ;;=========================================================================
  84. ;; Redefine the edebug reader to check whether CL syntax is active.
  85. ;; This might be a little cleaner using advice.
  86.  
  87. (defvar edebug-reading-with-cl-read nil)
  88.  
  89. (or (fboundp 'edebug-original-read-storing-offsets)
  90.     (defalias 'edebug-original-read-storing-offsets
  91.       (symbol-function 'edebug-read-storing-offsets)))
  92.  
  93. (defun edebug-read-storing-offsets (stream)
  94.   ;; Read a sexp from STREAM.
  95.   ;; STREAM is limited to the current buffer.
  96.   ;; Create a parallel offset structure as described in doc for edebug-offsets.
  97.   ;; This version, from edebug-cl-read, uses cl-read.
  98.   (if (not cl-read-active)
  99.       ;; Use the reader for standard Emacs Lisp.
  100.       (edebug-original-read-storing-offsets stream)
  101.     
  102.     ;; Use cl-read with edebug hooks.
  103.     (if edebug-reading-with-cl-read nil
  104.       ;; Only do this if it's not already been done, else it loops.
  105.       (fset 'edebug-reader::read-sexp-func
  106.         (symbol-function 'reader::read-sexp-func))
  107.       (fset 'reader::read-sexp-func 'edebug-read-sexp-func)
  108.       (fset 'edebug-reader::end-list-handler (get-macro-character ?\)))
  109.       (set-macro-character ?\) 'edebug-end-list-handler)))
  110.     (unwind-protect
  111.     (let ((edebug-reading-with-cl-read t))
  112.       (reader::read stream))
  113.       (if edebug-reading-with-cl-read nil
  114.     (set-macro-character 
  115.      ?\) (symbol-function 'edebug-reader::end-list-handler))
  116.     (fset 'reader::read-sexp-func
  117.           (symbol-function 'edebug-reader::read-sexp-func)))))
  118.  
  119.